// Package ioc
/**
* @Project : geektime-basic-go-study
* @File    : redis.go
* @IDE     : GoLand
* @Author  : Tvux
* @Date    : 2024/10/7 22:27
**/

package ioc

import (
	"geektime-basic-go-study/webook/backend/config"
	"github.com/redis/go-redis/v9"
	"github.com/spf13/viper"
)

func InitRedis() redis.Cmdable {
	redisConf := config.RedisConfig{
		DSN: "localhost:6379",
	}
	if err := viper.UnmarshalKey("config.redisConf", &redisConf); err != nil {
		panic(err)
	}
	return redis.NewClient(&redis.Options{
		Addr: viper.GetString(redisConf.DSN),
	})
}
